/*
 *
 */
package org.jiscinvolve.astrodabis.barberry.common.data;

import java.net.URI;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.junit.Test;
import org.junit.After;
import org.junit.Before;
import static org.junit.Assert.*;

/*
 *
 */
public class TapJoinTestCase
extends JoinTestBase
    {

    @Test
    public void checkCreated()
        {
        compare(
            rowone.joins().create(
                rowtwo
                ),
            rowone,
            rowtwo
            );
        }    

    @Test
    public void checkSelectFromRowOneByRowTwo()
        {
        compare(
            rowone.joins().create(
                rowtwo
                ),
            rowone.joins().select(
                rowtwo
                )
            );
        }

    //
    // LazyInitializationException
    // @Test
    public void checkSelectFromFactoryBySameRow()
        {
        assertNotNull(
            rowone.joins().create(
                rowtwo
                )
            );

        assertTrue(
            womble().joins().select(
                rowone,
                TapJoin.SelectType.SAME
                ).iterator().hasNext()
            );

        assertTrue(
            womble().joins().select(
                rowone,
                TapJoin.SelectType.BOTH
                ).iterator().hasNext()
            );

        assertFalse(
            womble().joins().select(
                rowone,
                TapJoin.SelectType.SWAP
                ).iterator().hasNext()
            );

        compare(
            rowone.joins().create(
                rowtwo
                ),
            womble().joins().select(
                rowone,
                TapJoin.SelectType.SAME
                ).iterator().next()
            );

        compare(
            rowone.joins().create(
                rowtwo
                ),
            womble().joins().select(
                rowone,
                TapJoin.SelectType.BOTH
                ).iterator().next()
            );
        }

    //
    // LazyInitializationException
    // @Test
    public void checkSelectFromFactoryBySwapRow()
        {
        assertNotNull(
            rowone.joins().create(
                rowtwo
                )
            );

        assertFalse(
            womble().joins().select(
                rowtwo,
                TapJoin.SelectType.SAME
                ).iterator().hasNext()
            );

        assertTrue(
            womble().joins().select(
                rowtwo,
                TapJoin.SelectType.BOTH
                ).iterator().hasNext()
            );

        assertTrue(
            womble().joins().select(
                rowtwo,
                TapJoin.SelectType.SWAP
                ).iterator().hasNext()
            );

        compare(
            rowone.joins().create(
                rowtwo
                ),
            womble().joins().select(
                rowtwo,
                TapJoin.SelectType.SWAP
                ).iterator().next()
            );

        compare(
            rowone.joins().create(
                rowtwo
                ),
            womble().joins().select(
                rowtwo,
                TapJoin.SelectType.BOTH
                ).iterator().next()
            );

        }
    }

